package com.snake.driver;

import com.snake.WebDriverUtil;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.util.Arrays;

/**
 * Created by Administrator on 2018/5/9 0009.
 */
public class TestGoods {
    private static WebDriver driver;
    public static void main(String[] args) throws InterruptedException {
        String browserDriverUrl = "E:\\chromedriver\\chromedriver.exe";// 浏览器驱动路径
        //启动chrome浏览器
        System.setProperty("webdriver.chrome.driver", browserDriverUrl);
        //取消 chrome正受到自动测试软件的控制的信息栏
        ChromeOptions options = new ChromeOptions();
        options.addArguments("disable-infobars");
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));
        options.addArguments("--test-type", "--start-maximized");

        driver = new ChromeDriver(options);
        driver.get("https://item.taobao.com/item.htm?id=579195334061");
        Thread.sleep(10000);


        String goodVideoSrc = "";
        By videoBy = By.className("tb-video");
        if (WebDriverUtil.elementExist(driver, videoBy)) {
            System.out.println("找到了视频播放按钮");
            Document pageSource = Jsoup.parse(driver.getPageSource());
            System.out.println(pageSource.html());
            Actions action=new Actions(driver);
            WebElement webElement = driver.findElement(videoBy);
            action.doubleClick(driver.findElement(By.xpath("//*[@id=\"detail\"]/div[1]/div[1]/div/div[1]/div[1]/div/div[2]/div/div[1]/button[2]"))).perform();

        }else{
            System.out.println("没有找到视频播放按钮");
        }
    }
}
